﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_News_ctrQuickTab : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.SetInitLabel();
            this.BindData();
        
        }
    }

    private void SetInitLabel()
    {
        int nCurrentLanguage = Support.GetCurrentLanguage()-1;
        lblEvent.Text = MultipleLanguage.LBL_EVENT[nCurrentLanguage];
        lblNews.Text = MultipleLanguage.LBL_NEWS[nCurrentLanguage];
        lblProfile.Text = MultipleLanguage.LBL_PROFILE[nCurrentLanguage];
        lnkNewsAll.Text = MultipleLanguage.VIEWALL[nCurrentLanguage];
        lnkNewsAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=28" ;

        lnkEventAll .Text = MultipleLanguage.VIEWALL[nCurrentLanguage];
        lnkEventAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=29";

        lnkProfileAll.Text = MultipleLanguage.VIEWALL[nCurrentLanguage];
        lnkProfileAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=30";

    }

    private void BindData()
    {
        int nItemView = 3;
        int nItem = 0;
        int nPageCount = 0;
        int nPageSize = 3;
        int nStatus = 1;
        int nNewsCat = 28;
        int nProfileCat = 30;
        int nEventCat = 29;
        int nPageIndex = 1;
        int nDefaultLanguage = Support.GetDefaultLanguage();
        int nCurrentLanguage = Support.GetCurrentLanguage();

        News objNews = new News();
        DataTable dtbNews = new DataTable();
        dtbNews = objNews.Search(nItemView, nItem, string.Empty, nNewsCat, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);
        dtlNews.DataSource = dtbNews;
        dtlNews.DataBind();

        News objProfile = new News();
        DataTable dtbProfile = new DataTable();
        dtbProfile = objProfile.Search(nItemView, nItem, string.Empty, nProfileCat, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);
        dtlProfile.DataSource = dtbProfile ;
        dtlProfile.DataBind();

        dtbNews = objNews.Search(nItemView, nItem, string.Empty, nEventCat, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);
        dtlEvent.DataSource = dtbNews;
        dtlEvent.DataBind();
    }

   
   
    protected void dtlNews_ItemDataBound1(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            ImageButton btnImage = (ImageButton)e.Item.FindControl("btnImage");
            HyperLink lnkTitle = (HyperLink)e.Item.FindControl("lnkTitle");
            Label lblInitContent = (Label)e.Item.FindControl("lblInitContent");
            Label lblDateCreated = (Label)e.Item.FindControl("lblDateCreated");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsID"));
            lnkTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsTitle"));
            string sInit = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            if (sInit.Length > 75)
            { sInit = ConvertData.TruncateString(sInit, 75) + "..."; }
            lblInitContent.Text = sInit;
            lnkTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + nID;
            lblDateCreated.Text = ConvertData.ConvertIntToDatetimeString(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CreatedDate")));
            btnImage.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsID"));
        }
    }
    protected void dtlNews_ItemCommand1(object source, DataListCommandEventArgs e)
    {
        string sCommand = e.CommandName;
        int nNewsID = ConvertData.ConvertToInt(e.CommandArgument);
        switch (sCommand)
        {
            case "image":
                string sNewsDetail = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + nNewsID;
                Response.Redirect(sNewsDetail);
                break;
        }
    }
    protected void dtlProfile_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            ImageButton btnImage = (ImageButton)e.Item.FindControl("btnImage");
            HyperLink lnkTitle = (HyperLink)e.Item.FindControl("lnkTitle");
            Label lblInitContent = (Label)e.Item.FindControl("lblInitContent");
            Label lblDateCreated = (Label)e.Item.FindControl("lblDateCreated");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsID"));
            lnkTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsTitle"));
            string sInit = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            if (sInit.Length > 75)
            { sInit = ConvertData.TruncateString(sInit, 75) + "..."; }
            lblInitContent.Text = sInit;
            lnkTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + nID;
            lblDateCreated.Text = ConvertData.ConvertIntToDatetimeString(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CreatedDate")));
            btnImage.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsID"));
        }
    }
    protected void dtlProfile_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string sCommand = e.CommandName;
        int nNewsID = ConvertData.ConvertToInt(e.CommandArgument);
        switch (sCommand)
        {
            case "image":
                string sNewsDetail = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + nNewsID;
                Response.Redirect(sNewsDetail);
                break;
        }
    }
    protected void dtlEvent_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            ImageButton btnImage = (ImageButton)e.Item.FindControl("btnImage");
            HyperLink lnkTitle = (HyperLink)e.Item.FindControl("lnkTitle");
            Label lblInitContent = (Label)e.Item.FindControl("lblInitContent");
            Label lblDateCreated = (Label)e.Item.FindControl("lblDateCreated");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsID"));
            lnkTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsTitle"));
            string sInit = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            if (sInit.Length > 75)
            { sInit = ConvertData.TruncateString(sInit, 75) + "..."; }
            lblInitContent.Text = sInit;
            lnkTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + nID;
            lblDateCreated.Text = ConvertData.ConvertIntToDatetimeString(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CreatedDate")));
            btnImage.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "NewsID"));
        }
    }
    protected void dtlEvent_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string sCommand = e.CommandName;
        int nNewsID = ConvertData.ConvertToInt(e.CommandArgument);
        switch (sCommand)
        {
            case "image":
                string sNewsDetail = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + nNewsID;
                Response.Redirect(sNewsDetail);
                break;
        }
    }
}
